package com.bachongLightNovel.message.config;

import com.bachongLightNovel.constant.RabbitmqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;

/**
 * @author vermouth
 */
public class RabbitmqConfig {

    //声明消息通知交换机
    @Bean
    public DirectExchange messageExchange(){
        return new DirectExchange(RabbitmqConstant.BACHONG_MESSAGE_EXCHANGE,true,false);
    }
    //声明消息接收队列
    @Bean
    public Queue messageQueue(){
        return QueueBuilder
                .durable(RabbitmqConstant.BACHONG_MESSAGE_QUEUE)
                .build();
    }
    //绑定交换机和队列
    @Bean
    public Binding bindingMessageDirect(Queue messageQueue,DirectExchange messageExchange){
        return BindingBuilder.bind(messageExchange)
                .to(messageExchange)
                .with(RabbitmqConstant.BACHONG_MESSAGE_KEY);
    }
}
